﻿{include file="../application/admin/view/common/header.html" /}
<style type="text/css">
    .radio-box {
        display: inline-block;
        width: 64px;
    }

    .formControls {
        padding-right: 50px;
        position: relative;
    }

    .textarea {
        height: 100px;
        resize: none;
        font-size: 14px;
        padding: 4px;
    }

    .textarea-numberbar {
        position: absolute;
        right: 70px;
        bottom: 5px;
        z-index: 1;
        margin-bottom: 0;
    }

    .bg-c {
        background-color: #23b7e5;
        color: #fff;
    }
</style>
<!--main content start-->
<section class="main-content">
    <!--start page content-->
    <div class="row">

        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="tabs">
                        <!-- Nav tabs -->
                        <ul class="list-inline tabs-nav" role="tablist">
                            <li role="presentation" id="email" class="active"><a href="#home" aria-controls="home"
                                                                                 role="tab" data-toggle="tab"
                                                                                 aria-expanded="true">电子邮件</a></li>
                            <li role="presentation" id="wechat" class=""><a href="#profile" aria-controls="profile"
                                                                            role="tab" data-toggle="tab"
                                                                            aria-expanded="false">微信支付</a></li>
                            <li role="presentation" id="alipay" class=""><a href="#messages" aria-controls="messages"
                                                                            role="tab" data-toggle="tab"
                                                                            aria-expanded="false">支付宝支付</a></li>
                        </ul>
                        <!-- Tab panes -->
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="home">
                                <form class="form form-horizontal" id="form1">
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">邮件服务是否要求加密链接（SSL）：</label>
                                        <div class="formControls col-xs-6 col-sm-5 skin-minimal">
                                            <div class="radio-box">
                                                <input name="e-login" class="ssl-1" type="radio" id="tr" value="1">
                                                <label for="tr">是</label>
                                            </div>
                                            <div class="radio-box">
                                                <input type="radio" class="ssl-2" id="fls" name="e-login" value="0">
                                                <label for="fls">否</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">发送邮件服务器地址（SMTP)：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" class="input-text" value="" placeholder="" id="smtp"
                                                   name="adminName">
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">服务器端口：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" class="input-text" value="13012345678" placeholder=""
                                                   id="port" name="phone">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">邮件发送账号：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" class="input-text" value="1234567899@qq.com"
                                                   placeholder="@" name="email" id="account">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">SMTP服务器用户名:</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" class="input-text" value="1234567899@qq.com"
                                                   placeholder="@" name="email" id="user">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">SMTP服务器密码:</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" class="input-text" value="1234567899@qq.com"
                                                   placeholder="@" name="email" id="password">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">邮件回复地址：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" class="input-text" value=""
                                                   placeholder="回复EMAIL（留空则为发件人EMAIL）" name="email" id="e-address">
                                        </div>
                                    </div>
                                    <!-- <div class="row cl">
                                        <label class="form-label col-xs-4 col-sm-3">角色：</label>
                                        <div class="formControls col-xs-6 col-sm-5"> <span class="select-box" style="width:150px;">
                                            <select class="select" name="adminRole" size="1">
                                                <option value="0">超级管理员</option>
                                                <option value="1">管理员</option>
                                                <option value="2">测试</option>
                                                <option value="3">新闻编辑</option>
                                                <option value="4">专利代理人</option>
                                            </select>
                                            </span> </div>
                                    </div> -->
                                    <div class="row cl">
                                        <div class="col-xs-8 col-sm-9 col-sm-9 col-xs-offset-5 col-sm-offset-5">
                                            <input class="btn btn-primary-email radius bg-c" type="button"
                                                   value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                                            <input class="btn radius" style="color: #ffffff;background-color: #a0a0a0;"
                                                   type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
                                        </div>
                                    </div>
                                </form>

                            </div>
                            <div role="tabpanel" class="tab-pane" id="profile">
                                <form class="form form-horizontal" id="form2">
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">启用微信登录:：</label>
                                        <div class="formControls col-xs-6 col-sm-5 skin-minimal">
                                            <div class="radio-box">
                                                <input name="w-login" type="radio" class="weixin-1" id="tr2" value="1">
                                                <label for="tr2">是</label>
                                            </div>
                                            <div class="radio-box">
                                                <input type="radio" id="fls2" class="weixin-2" name="w-login" value="0">
                                                <label for="fls2">否</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">标题：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" id="title" class="input-text" value="" placeholder=""
                                                   id="" name="">
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">服务类型：</label>
                                        <div class="formControls col-xs-6 col-sm-5"> <span class="select-box"
                                                                                           style="width:150px;">
                                                    <select class="select" id="type" name="type" size="1">
                                                        <option value="1" id="type-1">商品</option>
                                                        <option value="0" id="type-2">其他</option>
                                                    </select>
                                                    </span>
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">支付网关地址：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" id="address" class="input-text" value="" placeholder=""
                                                   name="">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">商家ID：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" id="shops_id" class="input-text" value="" placeholder=""
                                                   name="" id="">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">商家密钥：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="password" id="shops_key" class="input-text" value=""
                                                   placeholder="" name="" id="">
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">适用国家支付：</label>
                                        <div class="formControls col-xs-6 col-sm-5"> <span class="select-box"
                                                                                           style="width:150px;">
                                                    <select class="select" id="nation_pay" name="nation_pay" size="1">
                                                        <option value="0" id="nation_pay_0">选择国家</option>
                                                        <option value="1" id="nation_pay_1">中国</option>
                                                        <option value="2" id="nation_pay_2">英国</option>
                                                        <option value="3" id="nation_pay_3">美国</option>
                                                        <option value="4" id="nation_pay_4">日本</option>
                                                    </select>
                                                    </span>
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <div class="col-xs-8 col-sm-9 col-sm-9 col-xs-offset-5 col-sm-offset-5">
                                            <input class="btn btn-primary-weixin radius bg-c" type="submit"
                                                   value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                                            <input class="btn radius" style="color: #ffffff;background-color: #a0a0a0;"
                                                   type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
                                        </div>
                                    </div>
                                </form>

                            </div>
                            <div role="tabpanel" class="tab-pane" id="messages">
                                <form class="form form-horizontal" id="form3">
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">启用支付宝登录:</label>
                                        <div class="formControls col-xs-6 col-sm-5 skin-minimal">
                                            <div class="radio-box">
                                                <input name="a-login" class="alipay-1" type="radio" id="tr2" value="1">
                                                <label for="tr2">是</label>
                                            </div>
                                            <div class="radio-box">
                                                <input type="radio" class="alipay-2" id="fls2" name="a-login" value="0">
                                                <label for="fls2">否</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">标题：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" id="a-title" class="input-text" value="" placeholder=""
                                                   name="">
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">服务类型：</label>
                                        <div class="formControls col-xs-6 col-sm-5"> <span class="select-box"
                                                                                           style="width:150px;">
                                                    <select class="select" id="a-type" name="" size="1">
                                                        <option value="0" id="a-type-1">商品</option>
                                                        <option value="1" id="a-type-2">其他</option>
                                                    </select>
                                                    </span>
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">支付网关地址：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" id="a-address" class="input-text" value="" placeholder=""
                                                   name="">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">商家ID：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="text" id="a_shops_id" class="input-text" value=""
                                                   placeholder="" name="">
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">商家密钥：</label>
                                        <div class="formControls col-xs-6 col-sm-5">
                                            <input type="password" id="a_shops_key" class="input-text" value=""
                                                   placeholder="" name="">
                                        </div>
                                    </div>

                                    <div class="row cl">
                                        <label class="form-label col-xs-5 col-sm-5">适用国家支付：</label>
                                        <div class="formControls col-xs-6 col-sm-5"> <span class="select-box"
                                                                                           style="width:150px;">
                                                    <select class="select" id="a_nation_pay" name="adminRole" size="1">
                                                        <option value="0" id="a_nation_pay_0">选择国家</option>
                                                        <option value="1" id="a_nation_pay_1">中国</option>
                                                        <option value="2" id="a_nation_pay_2">英国</option>
                                                        <option value="3" id="a_nation_pay_3">美国</option>
                                                        <option value="4" id="a_nation_pay_4">日本</option>
                                                    </select>
                                                    </span>
                                        </div>
                                    </div>
                                    <div class="row cl">
                                        <div class="col-xs-8 col-sm-9 col-sm-9 col-xs-offset-5 col-sm-offset-5">
                                            <input class="btn btn-primary-alipay radius bg-c" type="button"
                                                   value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                                            <input class="btn radius" style="color: #ffffff;background-color: #a0a0a0;"
                                                   type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
                                        </div>
                                    </div>
                                </form>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div><!--end row-->
    <!--end page content-->
</section>
<!--end main content-->
<!--Common plugins-->
<script src="_JS_/jquery.min.js"></script>
<script src="_JS_/jquery.base64.js"></script>
<script src="_JS_/jquery.cookie.js"></script>
<script src="_JS_/bootstrap.min.js"></script>
<script src="_JS_/jasny-bootstrap.min.js"></script>
<script src="_JS_/jquery.slimscroll.min.js"></script>
<script src="_JS_/jquery.nanoscroller.min.js"></script>
<script src="_JS_/metismenu.min.js"></script>
<script src="_JS_/float-custom.js"></script>
<script type="text/javascript" src="_JS_/layer/layer.js"></script>
<!-- <script src="js/footable.all.min.js"></script> -->
<!-- Page-Level Scripts -->
<script>
    $(function () {
        $("#page-title").html("密钥管理");
    })
    $(function () {
        get('email', '1');
    });

    $('#email').click(function () {
        get('email', '1');
    });

    $('#wechat').click(function () {
        get('weichat', '2');
    });

    $('#alipay').click(function () {
        get('alipay', '3');
    });

    function get(name, status) {
        $.ajax({
            type: "get",
            url: "{:url('api/keys/index')}",
            dataType: "jsonp",
            jsonp: "callback",
            data: {'name': name},
            success: function (msg) {
                $("#system_management").addClass("active").children("ul").addClass("in");
                $("#keys_management").addClass("choose");
                if (msg.code == 200) {
                    var data = msg['data'];
                    put(data, status);
                } else {
                    layer.msg('数据获取失败，请刷新重试！', {icon: 2, time: 1000});
                }
            },
            error: function () {
                layer.msg('网络错误');
            },
        });
    }

    function put(data, status) {
        if (status == 1) {
            if (data['ssl'] == 1) {
                $('.ssl-1').attr('checked', 'checked');
            } else {
                $('.ssl-2').attr('checked', 'checked');
            }
            $('#smtp').val(data['smtp']);
            $('#port').val(data['port']);
            $('#account').val(data['account']);
            $('#user').val(data['user']);
            $('#password').val(data['password']);
            $('#e-address').val(data['address']);
        } else if (status == 2) {
            if (data['login'] == 1) {
                $('.weixin-1').attr('checked', 'checked');
            } else {
                $('.weixin-2').attr('checked', 'checked');
            }
            $('#title').val(data['title']);

            var type = data['type'];
            if (type == 1) {
                $('#type-1').attr('selected', 'selected');
            } else {
                $('#type-2').attr('selected', 'selected');
            }
            $('#address').val(data['address']);
            $('#shops_id').val(data['shops_id']);
            $('#shops_key').val(data['shops_key']);
            var nation_pay = parseInt(data['nation_pay']);
            switch (nation_pay) {
                case 0:
                    $('#nation_pay_0').attr('selected', 'selected');
                    break;
                case 1:
                    $('#nation_pay_1').attr('selected', 'selected');
                    break;
                case 2:
                    $('#nation_pay_2').attr('selected', 'selected');
                    break;
                case 3:
                    $('#nation_pay_3').attr('selected', 'selected');
                    break;
                case 3:
                    $('#nation_pay_4').attr('selected', 'selected');
                    break;

            }
        } else {
            if (data['login'] == 1) {
                $('.alipay-1').attr('checked', 'checked');
            } else {
                $('.alipay-2').attr('checked', 'checked');
            }
            $('#a-title').val(data['title']);

            var a_type = data['type'];
            if (a_type == 1) {
                $('#a-type-1').attr('selected', 'selected');
            } else {
                $('#a-type-2').attr('selected', 'selected');
            }
            $('#a-address').val(data['address']);
            $('#a_shops_id').val(data['shops_id']);
            $('#a_shops_key').val(data['shops_key']);
            var a_nation_pay = parseInt(data['nation_pay']);
            switch (a_nation_pay) {
                case 0:
                    $('#a_nation_pay_0').attr('selected', 'selected');
                    break;
                case 1:
                    $('#a_nation_pay_1').attr('selected', 'selected');
                    break;
                case 2:
                    $('#a_nation_pay_2').attr('selected', 'selected');
                    break;
                case 3:
                    $('#a_nation_pay_3').attr('selected', 'selected');
                    break;
                default:
                    $('#a_nation_pay_4').attr('selected', 'selected');
            }
        }
    }

    /*邮箱*/
    $('.btn-primary-email').on('click', function () {
        var login = $("input[name=e-login]:checked").val();
        // alert(login);return false;
        smtp = $("#smtp").val();
        port = $("#port").val();
        account = $("#account").val();
        user = $("#user").val();
        password = $("#password").val();
        address = $("#e-address").val();

        $.ajax({
            type: 'get',
            dataType: 'jsonp',
            jsonp: 'callback',
            url: "{:url('api/Keys/edit_f')}",
            data: {
                'login': login,
                'smtp': smtp,
                'port': port,
                'account': account,
                'user': user,
                'password': password,
                'address': address,
                'table': 'email'
            },
            success: function (msg) {
                if (msg.code == 200) {
                    layer.msg('提交成功', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg(msg.message, {icon: 2, time: 1000});
                }
            },
            error: function () {
                layer.msg('网络错误');
            },
        });
    });

    /*微信*/
    $('.btn-primary-weixin').on('click', function () {
        var login = $("input[name=w-login]:checked").val();
        // alert(login);return false;
        title = $("#title").val();
        type = $("#type option:selected").val();
        address = $("#address").val();
        shops_id = $("#shops_id").val();
        shops_key = $("#shops_key").val();
        nation_pay = $("#nation_pay option:selected").val();
        // alert(nation_pay);return false;
        $.ajax({
            type: 'get',
            dataType: 'jsonp',
            jsonp: 'callback',
            url: "{:url('api/Keys/edit_s')}",
            data: {
                'login': login,
                'title': title,
                'type': type,
                'address': address,
                'shops_id': shops_id,
                'shops_key': shops_key,
                'nation_pay': nation_pay,
                'table': 'weichat'
            },
            success: function (msg) {
                if (msg.code == 200) {
                    layer.msg('提交成功', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg('提交失败', {icon: 2, time: 1000});
                }
            },
            error: function () {
                layer.msg('网络错误');
            },
        });
    });

    /*支付宝*/
    $('.btn-primary-alipay').on('click', function () {
        var login = $("input[name=a-login]:checked").val();
        // alert(login);return false;
        title = $("#a-title").val();
        type = $("#a-type option:selected").val();
        // alert(type);return false;
        address = $("#a-address").val();
        shops_id = $("#a_shops_id").val();
        shops_key = $("#a_shops_key").val();
        nation_pay = $("#a_nation_pay option:selected").val();
        // alert(nation_pay);return false;
        $.ajax({
            type: 'get',
            dataType: 'jsonp',
            jsonp: 'callback',
            url: "{:url('api/Keys/edit_s')}",
            data: {
                'login': login,
                'title': title,
                'type': type,
                'address': address,
                'shops_id': shops_id,
                'shops_key': shops_key,
                'nation_pay': nation_pay,
                'table': 'alipay'
            },
            success: function (msg) {
                if (msg.code == 200) {
                    layer.msg('提交成功', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg('提交失败', {icon: 2, time: 1000});
                }
            },
            error: function () {
                layer.msg('网络错误');
            },
        });
    });

</script>
</body>
</html>